home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / castools.zip / FAXFREEE.C < prev    next >
Text File  |  1990-01-05  |  2KB  |  70 lines

  1.  
  2.  
  3. /*
  4.    FAXFREEE.C  A high-level CAS Toolkit function.
  5.  
  6.    This function frees all the memory used by it's parameter, an Event
  7.    Control Structure.
  8.  
  9.    INPUT:  A complete Event Control Structure.
  10.  
  11.    OUTPUT: SUCCESS or FAIL.
  12. */
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <malloc.h>
  17. #include <cas.h>
  18. #include <fax.h>
  19.  
  20. int pascal FAXFreeECS(ECS *SourceECS)
  21. {
  22.   int CoverLength = SourceECS->EventControlFile.FTROffset - 383;
  23.   FTRLIST *CurrFTRL, *LastFTRL;
  24.   int i,
  25.       FileCount = SourceECS->EventControlFile.FileCount;
  26.  
  27.   FAXerrno = CASerrorcode = 0;      /* They keep it if nothing goes wrong */
  28.  
  29.   if (!SourceECS) {
  30.     FAXerrno = INVALIDPTR;
  31.     return(FAIL);
  32.   }
  33.   /* If there is an FTRLIST,  free FTRL's, up to FileCount or last FTRL */
  34.   if (SourceECS->FirstFTR) {
  35.     if (!FileCount) {
  36.       FAXerrno = MOREFTRSTHANFC;
  37.     }
  38.     LastFTRL = SourceECS->FirstFTR;
  39.     for (i=1; ((LastFTRL->next) && (i < FileCount)) ; i++) {  /* find last */
  40.       LastFTRL = LastFTRL->next;
  41.     }
  42.  
  43.     /* Following errors are warnings only: go ahead and free what's possible */
  44.     if (LastFTRL->next) {
  45.       FAXerrno = MOREFTRSTHANFC;           /* last FTRL doesn't point to NULL */
  46.       LastFTRL->next = NULL;
  47.     }
  48.     if (i < FileCount) {
  49.       FAXerrno = BADFILECOUNT;             /* FileCount exceeds FTRL's */
  50.     }
  51.  
  52.     /* Free them, from last backwards, until only the first is left */
  53.     free_FTRLIST(SourceECS->FirstFTR);
  54.   }
  55.   else {
  56.     if (FileCount) {
  57.       FAXerrno = BADFILECOUNT;
  58.     }
  59.   }
  60.  
  61.   /* Next, the coverpage text.  */
  62.   if (CoverLength) {
  63.     free(SourceECS->CoverPageText);
  64.   }
  65.  
  66.   /* Finally, the Event Control Structure itself */
  67.   free (SourceECS);
  68.   return(SUCCESS);
  69. }
  70.